package mongorest

import (
	"encoding/json"
	"log"
	"os"
)

const settingsPath = ".mongorest.json"

var settings *Settings

func pretty(value interface{}) string {
	if s, ok := value.(string); ok {
		return s
	}
	valueJson, err := json.MarshalIndent(value, "", "  ")
	if err != nil {
		log.Fatal(err)
	}
	return string(valueJson)
}

func newSettings(settingsFname string) (*Settings, error) {
	file, err := os.Open(settingsFname)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	settings := &Settings{
		BindIP: "localhost",
		Port:   8080,
	}
	err = json.NewDecoder(file).Decode(settings)
	return settings, err
}
